package sw.mylife;

import sw.mylife.system.MyLog;
import sw.mylife.system.Skillbook;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;

public class MyLife extends Activity implements OnClickListener{
	
	//Attribute----------------------------
	ImageView btn_bottom_community, btn_bottom_sb, btn_bottom_analysis,
			btn_bottom_profile;
	
	//Activity Standard Attribute
	private final Gui myGui = Gui.getMygui();
	private final Skillbook sb = Skillbook.getMySB();
	private static final String LOGTAG = "Gui: MyLife";
	
	//SyncService
	SyncServiceConnection ssc = new SyncServiceConnection();
	private ArrayAdapter<String> adapter;


	
	//Methoden-----------------------------
	@Override
	public void onCreate(Bundle savedInstanceState) {

		// Android Commands
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_my_life);

		// ++Layout links
		btn_bottom_community = (ImageView) findViewById(R.id.mylife_btn_community);
		btn_bottom_analysis = (ImageView) findViewById(R.id.mylife_btn_analysis);
		btn_bottom_sb = (ImageView) findViewById(R.id.mylife_btn_sb);
		btn_bottom_profile = (ImageView) findViewById(R.id.mylife_btn_profile);

		// ++Action Listener
		btn_bottom_community.setOnClickListener(this);
		btn_bottom_analysis.setOnClickListener(this);
		btn_bottom_sb.setOnClickListener(this);
		btn_bottom_profile.setOnClickListener(this);
		

		// ++Gui Settings
		btn_bottom_community.setAlpha(180);
		btn_bottom_analysis.setAlpha(180);
		btn_bottom_profile.setAlpha(180);
		btn_bottom_sb.setAlpha(180);
		
		MyLog.v(LOGTAG, "MyLife Seite wurde komplett initialisiert");
		
		//Starten des SyncService
		//TODO Find out what is an Adapter
		/*adapter = new ArrayAdapter<String>(this,
		        android.R.layout.simple_list_item_1, android.R.id.text1,
		        wordList);
		setListAdapter(adapter);*/
		Intent i = new Intent(this, SyncService.class);
		startService(i);
		doBindService();
	}
	
	@Override
	protected void onStop() {
		super.onStop();
		unbindService(ssc);
	};

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_my_life, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		if (v == btn_bottom_sb) {
			btn_bottom_sb.setBackgroundColor(Color.CYAN);
		}

	}
	
	void doBindService(){
		bindService(new Intent(this, SyncService.class), ssc, Context.BIND_AUTO_CREATE);
	}
	
	
	//TODO: der Receiver muss noch einen Broadcast empfangen, bevor es losgeht... 
	//vll muss bind danach geschehen
	public void showServiceData(View v){
		if(ssc != null){
			MyLog.v(LOGTAG, "Lade Daten vom Service...");
			
			//ADAPTER FIND OUT
			//adapter.notifyDataSetChanged();
		}
	}
	
	
}
